home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / dfpp01.zip / SCREEN.CPP < prev    next >
C/C++ Source or Header  |  1992-11-21  |  4KB  |  147 lines

  1. // ----------- screen.cpp
  2.  
  3. #include <string.h>
  4. #include "desktop.h"
  5.  
  6. Screen::Screen()
  7. {
  8.     if (isEGA() || isVGA())    {
  9.         // --- turn blinking off
  10.         regs.x.ax = 0x1003;
  11.         regs.h.bl = 0;
  12.         int86(VIDEO, ®s, ®s);
  13.     }
  14.     // ---- get the video mode and page
  15.     regs.h.ah = 15;
  16.     int86(VIDEO, ®s, ®s);
  17.     mode = regs.h.al;
  18.     page = regs.x.bx;
  19.     page &= 0xff00;
  20.     mode &= 0x7f;
  21.     // ---- Monochrome Display Adaptor or text mode
  22.     if (isMono())
  23.         address = 0xb000;
  24.     else
  25.         // ------ Text mode
  26.         address = 0xb800 + page;
  27.     width = *(unsigned char far *)( MK_FP(0x40,0x4a) );
  28.     if (isVGA() || isEGA())
  29.         height = *(unsigned char far *)( MK_FP(0x40,0x84) )+1;
  30.     else
  31.         height = 25;
  32. }
  33.  
  34. // ---- test for EGA
  35. Bool Screen::isEGA(void)
  36. {
  37.     if (isVGA())
  38.         return False;
  39.     regs.h.ah = 0x12;
  40.     regs.h.bl = 0x10;
  41.     int86(VIDEO, ®s, ®s);
  42.     return (Bool) (regs.h.bl != 0x10);
  43. }
  44.  
  45. // ---- test for VGA
  46. Bool Screen::isVGA(void)
  47. {
  48.     regs.x.ax = 0x1a00;
  49.     int86(VIDEO, ®s, ®s);
  50.     return (Bool) (regs.h.al == 0x1a && regs.h.bl > 6);
  51. }
  52.  
  53. // --------- scroll the screen d: 1 = up, 0 = dn
  54. void Screen::Scroll(Rect &rc, int d, int fg, int bg)
  55. {
  56.     desktop.mouse().Hide();
  57.     regs.h.cl = rc.Left();
  58.     regs.h.ch = rc.Top();
  59.     regs.h.dl = rc.Right();
  60.     regs.h.dh = rc.Bottom();
  61.     regs.h.bh = clr(fg,bg);
  62.     regs.h.ah = 7 - d;
  63.     regs.h.al = 1;
  64.     int86(VIDEO, ®s, ®s);
  65.     desktop.mouse().Show();
  66. }
  67.  
  68. // -------- read a character of video memory
  69. unsigned int Screen::GetVideoChar(int x, int y)
  70. {
  71.     int c;
  72.     desktop.mouse().Hide();
  73.     c = peek(address, vad(x,y));
  74.     desktop.mouse().Show();
  75.     return c & 255;
  76. }
  77.  
  78. // -------- write a character of video memory
  79. void Screen::PutVideoChar(int x, int y, unsigned int c)
  80. {
  81.     if (x < width && y < height)    {
  82.         desktop.mouse().Hide();
  83.         poke(address, vad(x,y), c);
  84.         desktop.mouse().Show();
  85.     }
  86. }
  87.  
  88. // --------- Write a string to video memory
  89. void Screen::WriteVideoString(char *s,int x,int y,int fg,int bg)
  90. {
  91.     if (x < width && y < height)    {
  92.         int len = strlen(s);
  93.         int *ln = new int[len];
  94.         int *cp1 = ln;
  95.         int col = clr(fg,bg) << 8;
  96.         while (*s)    {
  97.             *cp1++ = (*s & 255) | col;
  98.             s++;
  99.         }
  100.         if (x + len >= width)
  101.             len = width - x;
  102.         desktop.mouse().Hide();
  103.         movedata(FP_SEG(ln),FP_OFF(ln),address,vad(x,y),len*2);
  104.         desktop.mouse().Show();
  105.         delete [] ln;
  106.     }
  107. }
  108.  
  109. // -- read a rectangle of video memory into a save buffer
  110. void Screen::GetBuffer(Rect &rc, char *bf)
  111. {
  112.     if (rc.Left() >= width || rc.Top() >= height)
  113.         return;
  114.     int ht = rc.Bottom()-rc.Top()+1;
  115.     int bytes_row = (rc.Right()-rc.Left()+1) * 2;
  116.     unsigned vadr = vad(rc.Left(), rc.Top());
  117.     desktop.mouse().Hide();
  118.     while (ht--)    {
  119.         movedata(address, vadr, FP_SEG(bf),
  120.                 FP_OFF(bf), bytes_row);
  121.         vadr += width*2;
  122.         bf = (char far *)bf + bytes_row;
  123.     }
  124.     desktop.mouse().Show();
  125. }
  126.  
  127. // -- write a rectangle of video memory from a save buffer
  128. void Screen::PutBuffer(Rect &rc, char *bf)
  129. {
  130.     if (rc.Left() >= width || rc.Top() >= height)
  131.         return;
  132.     int ht = rc.Bottom()-rc.Top()+1;
  133.     int bytes_row = (rc.Right()-rc.Left()+1) * 2;
  134.     unsigned vadr = vad(rc.Left(), rc.Top());
  135.     desktop.mouse().Hide();
  136.     while (ht--)    {
  137.         movedata(FP_SEG(bf), FP_OFF(bf), address,
  138.                 vadr, bytes_row);
  139.         vadr += width*2;
  140.         bf += bytes_row;
  141.     }
  142.     desktop.mouse().Show();
  143. }
  144.  
  145.  
  146.  
  147.